<template>
  <div :class="styles.setting">
    <Cell @click="toOrder" title="我的订单">
      <template v-slot:leftIcon>
        <i :class="styles.iconStyle" class="iconfont icon-dingdan"></i>
      </template>
    </Cell>
    <Cell @click="toMyCollect" title="我的收藏">
      <template v-slot:leftIcon>
        <i :class="styles.iconStyle" class="iconfont icon-weishoucang"></i>
      </template>
    </Cell>
    <Cell @click="toOrder" border title="隐私设置">
      <template v-slot:leftIcon>
        <i :class="styles.iconStyle" class="iconfont icon-kejian"></i>
      </template>
    </Cell>
    <Cell title="分享好友">
      <template v-slot:leftIcon>
        <i :class="styles.iconStyle" class="iconfont icon-fenxiang"></i>
      </template>
      <template v-slot:rightSlot>
        <button :class="styles.share" open-type="share">分享领红包</button>
      </template>
    </Cell>
    <Cell @click="toCall" title="联系客服">
      <template v-slot:leftIcon>
        <i :class="styles.iconStyle" class="iconfont icon-kefu"></i>
      </template>
    </Cell>
    <view v-if="isAdmin" :class="styles.buttonWrap">
      <van-button plain @click="toAdmin" block>商户后台管理</van-button>
    </view>
  </div>
</template>

<script lang="ts">
import { computed } from 'vue';
import Taro, { useShareAppMessage } from '@tarojs/taro';
import { Cell } from '@/components';
import { useUser } from '@/stores';
import { defaultShareImage } from '@/const/images';
import { ADMIN_URL } from '@/const/h5';
import styles from './index.module.less';

export default {
  components: {
    Cell,
  },
  setup() {
    const userStore = useUser();

    const isAdmin = computed(() => {
      return (
        userStore.userinfo.phone === '18612135207' || userStore.userinfo.phone === '13666588689'
      );
    });

    const toOrder = () => {
      Taro.showToast({
        title: '系统升级中',
        icon: 'none',
      });
    };

    const toCall = () => {
      Taro.makePhoneCall({
        phoneNumber: '13666588689',
      });
    };

    useShareAppMessage(() => {
      return {
        title: '阿姨直聘',
        path: `/pages/index/index`,
        imageUrl: defaultShareImage,
      };
    });

    const toMyCollect = () => {
      Taro.navigateTo({
        url: '/subpackages/collect/index',
      });
    };

    const toAdmin = () => {
      Taro.navigateTo({
        url: `/pages/webview/index?redirect=${encodeURIComponent(ADMIN_URL)}`,
      });
    };

    return {
      styles,
      isAdmin,
      toCall,
      toOrder,
      toMyCollect,
      toAdmin,
    };
  },
};
</script>
